<template>
  <div class="category">
    <bread separator=">">
      <bread-item to="/">首页</bread-item>
      <bread-item>{{ cateName }}</bread-item>
    </bread>
    <div class="category-banner">
      <carousel :swiper="swiper" :autoplay="false"></carousel>
    </div>
    <!-- 所有二级分类 -->
    <div class="sub-list">
      <h3>全部分类</h3>
      <ul>
        <li v-for="item in cateList" :key="item.id">
          <RouterLink :to="`/category/sub/${item.id}`">
            <img :src="item.picture" />
            <p>{{ item.name }}</p>
          </RouterLink>
        </li>
      </ul>
    </div>

    <!-- 一级类目 -->
    <div class="ref-goods" v-for="obj in cateList" :key="obj.id">
      <div class="head">
        <h3>{{ obj.name }}</h3>
        <p class="tag">温暖柔软，品质之选</p>
        <more />
      </div>
      <div class="body" >
        <goods-item v-for="goods in obj.goods" :key="goods.id" :goods="goods"></goods-item>
      </div>

    </div>
  </div>
</template>

<script setup>
import { getCarouselAPI, getCategoryAPI } from '@/api'
import { ref } from 'vue'
import { useRoute } from 'vue-router'

const route = useRoute()
// console.log(route.params.id)
// const params = ref('')
// params.value = `/category/${route.params.id}`

const swiper = ref([])
const getCarouselFn = async () => {
  const res = await getCarouselAPI()
  swiper.value = res.result
}
getCarouselFn()

const cateList = ref([])
const cateName = ref('')
const getCategoryFn = async () => {
  const res = await getCategoryAPI(route.params.id)

  cateList.value = res.result.children
  // console.log(res.result.children)
  cateName.value = res.result.name
  // console.log(res.result.name)
}
getCategoryFn()
</script>

<style scoped lang="less">
.category {
  width: 1200px;
  margin: 0 auto;
}
.category-banner {
  //   width: 1240px;
  height: 500px;
  //   position: absolute;
  //   left: 0;
  //   top: 0;
  //   z-index: 98;
  background-color: #ccc;
}
// :deep(.carousel-btn.prev) {
//   left: 270px!important;
// }
// :deep(.carousel-indicator) {
//   padding-left: 250px;
// }
h3 {
  font-size: 28px;
  color: #666;
  font-weight: normal;
  text-align: center;
  line-height: 100px;
}
.sub-list {
  margin-top: 20px;
  background-color: #fff;
  ul {
    display: flex;
    padding: 0 32px;
    flex-wrap: wrap;
    li {
      width: 168px;
      height: 160px;
      a {
        text-align: center;
        display: block;
        font-size: 16px;
        img {
          width: 100px;
          height: 100px;
        }
        p {
          line-height: 40px;
        }
        &:hover {
          color: @xtxColor;
        }
      }
    }
  }
}
.ref-goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;
    .head {
      .xtx-more {
        position: absolute;
        top: 20px;
        right: 20px;
      }
      .tag {
        text-align: center;
        color: #999;
        font-size: 20px;
        position: relative;
        top: -20px;
      }
    }
    // .goods{
    //   display: flex;
    // }

}
.body {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      padding: 0 50px 30px;
    }
</style>
